function x = getDataStumps()   
        
    % Window Size - make sure it's an even value
    windowSize = 100;
    
    % Number of iterations for Adaboost.
    nIter = 150;
    
    % Normalize the train data?
    fnorm = false;
    
    % Number of cluster centers.
    nCenters = 10;
    
%% 
% Feature Extraction for performing clustering and adaboost
% classification.
    load subjectKey;
    load activityKey;
    
%     for subj=1:length(subjectKey) %#ok<USENS>
%         feat = [];
%         label = [];
%         for act=1:length(activityKey) %#ok<USENS>
%             % Set the filenames and variable names to be used
%             fileName = sprintf('%s-%s',activityKey{act},subjectKey{subj});
%             load(sprintf('%s-0.txt',fileName));
%             load(sprintf('%s-1.txt',fileName));
%             load(sprintf('./annotation/%s.txt',fileName));
% 
%             % Extract data
%             varName = fileName;
%             varName(find(varName == '-')) = '_';
%             actName = substring(varName, 0, find(varName == '_',1)-2);
% 
%             data1 = eval(sprintf('%s_0',varName));
%             data2 = eval(sprintf('%s_1',varName));
%             annotation = eval(varName);
% 
%             % Extract current label of activity
%             activityLabel = 0;
%             for i=1:length(activityKey)
%                 if strcmp(activityKey{i}, actName)
%                     activityLabel = i;
%                     break;
%                 end;
%             end
% 
%             % Extract features for every 100 samples with 50 samples overlapping
%             % from both the accelerometer data
%             index = 1;           
%             for i=1:(0.5*windowSize):size(data1,1)-windowSize
%                 tmp_feat = computestatfeatures([data1(i:i+windowSize-1,:),data2(i:i+windowSize-1,:)]);
%                 tmp_label = 0;
%                 if index <= size(annotation,1)
%                     if i >= annotation(index,1) && i <= annotation(index,2)
%                         tmp_label = activityLabel;
%                     elseif i > annotation(index,2)
%                         % Increase index values for annotation, reduce i by 50 and 
%                         % come back. This eliminates an extra index within bounds 
%                         % check for annotation matrix
%                         index = index+1;
%                         i = i-(0.5*windowSize); 
%                     end;
%                 end;
%                 feat = [feat;tmp_feat];
%                 label = [label;tmp_label];
%             end;
%         end;
%         save(sprintf('feat%d.mat',subj),'feat','label');
%     end;    
    
%% Perform a clustering of the features, and associate every frame with the
% cluster label. Train AdaBoost to learn each of the clusters.Use the 
% decision stumps from adaboost to derive the feature functions for training CRF.
%% Obtain stumps built using Adaboost

for fold = 1 : 1%length(subjectKey) 
%     % Create the train and test data set.
%     trdata = [];
%     trlabel = [];
%     tstdata = [];
%     tstlabel = [];
%     
%     for j = 1 : length(subjectKey)
%         load(sprintf('feat%d.mat',j));
%         % Subject Independent
%         if fold == j
%             tstdata = feat;
%             tstlabel = label;
%         else
%             trdata = [trdata;feat];
%             trlabel = [trlabel;label];
%         end       
%     end
%   
%     % normalize the training and the test data.
%     if fnorm
%         [trdata maxc minc] = normalizedata(trdata);
%         [tstdata maxc minc] = normalizedata(tstdata, maxc, minc);
%     end
%     
%    % Use K-Means and learn the clusters.
%    [model{fold} clabels{fold}] = cmeans(trdata',nCenters);
%    
%    % Use the learnt centers to determine the labels for the test data.
%    ctstlabel{fold} = knnclass(tstdata',model{fold});
%    
%    % Create the binary boosted classifiers for each of the actions using
%    % the labels obtained through clustering.
%    act_model{fold} = trainadaboost(trdata,clabels{fold},nCenters,nIter);
%        
%    % Multi class model evaluation with test data on the labels generated through clustering. 
%    [error(fold) accuracy(fold) yest{fold}] = eval_multiclass_boost(tstdata,ctstlabel{fold},act_model{fold},nIter);
%    
%    disp(sprintf('AdaBoost Fold %d Accuracy %f',fold,accuracy(fold)));
%    % Using the learnt decision stumps compute the binary features for the
%    % trdata and tstdata for training CRF
%    bin_trdata = calcBinFeat(trdata, act_model{fold});
%    bin_tstdata = calcBinFeat(tstdata, act_model{fold});
%    
%    bin_trdata = splitLongSeqIntoManyShort(bin_trdata',1000);
% %    bin_tstdata = splitLongSeqIntoManyShort(bin_tstdata',1000);
%    
%    ctrlabel = splitLongSeqIntoManyShort(trlabel',1000);
% %    ctstlabel = splitLongSeqIntoManyShort(tstlabel,1000);
%    
%    
%    alphaVals = extractAlpha(act_model{fold});
%    w = repmat(alphaVals,1,length(activityKey));
%    pot = rand(length(activityKey),length(activityKey));
%    
%    curExp.trainFeatMat = bin_trdata;
%    curExp.trainLabels = ctrlabel;
%    
%    curExp.modelInfo.numAct = length(activityKey);
%    curExp.modelInfo.numSense = size(bin_trdata,2);
%    
%    curExp.initialCRFLambda = [w(:);pot(:)];
%    
%    
%    curExp.testFeatMat = bin_tstdata';
%    curExp.testLabels = tstlabel;
   
%    save('CurExp','curExp');

load('CurExp');
   
   tic
   output.training = linchaincrfTrain(curExp);
   toc
   
   
   tic
   output.testing = linchaincrfTest(curExp, output.training.learnedParams);
   toc
end

%% Computestatfeatures
% computes mean, variance, correlation, energy and entropy
function feature = computestatfeatures(data)

% mean of the data
m = mean(data);

% variance of the data
v = var(data);

% correlation between the axis.
c = corr(data);

% absolute value of the fourier transform.
fftdata = abs(fft(data));

% remove the mean value.
fftdata = fftdata(2:end,:);

% energy.
e = sum(fftdata.^2)/size(fftdata,1);

% spectral entropy
fftdata = 1 + fftdata/size(data,1);
temp = [fftdata(:,1)/sum(fftdata(:,1)), fftdata(:,2)/sum(fftdata(:,2)),...
                                        fftdata(:,3)/sum(fftdata(:,3)),...
                                        fftdata(:,4)/sum(fftdata(:,4))...
                                        fftdata(:,5)/sum(fftdata(:,5))...
                                        fftdata(:,6)/sum(fftdata(:,6))];
ent = -sum(temp.*log(temp),1);

%feature = [m v c(1,2) c(1,3) c(2,3) e ent];
feature = [m v c(1,2:6) c(2,3:6) c(3,4:6) c(4,5:6) c(5,6) e ent];
return;
%%
function binFeat = calcBinFeat(data, actModel)
    binFeat = [];
    for index = 1:length(actModel)
        for count = 1:length(actModel{index})
            temp = eval_stump(actModel{index}{count},data);
            binFeat = [binFeat temp];
        end;        
    end;
return;
%%
function alphaVals = extractAlpha(actModel)
    alphaVals = [];
    for index = 1:length(actModel)
        for count = 1:length(actModel{index})
            alphaVals = [alphaVals; actModel{index}{count}.alpha];
        end;
    end;
return;
